package cn.com.io.day20151214.pojo;

import java.io.*;
import java.util.ArrayList;

/**
 * Created by Administrator on 2015/12/12.
 */
public class Computer implements Serializable{
    private String brand;
    private String ad;
    private double price;

    /**
     * 重写writeReplace方法，程序在序列化该对象之前，先调用该方法
     * @return
     * @throws ObjectStreamException
     */
    private  Object writeReplace() throws ObjectStreamException{
        ArrayList<Object> list = new ArrayList<Object>();
        list.add(brand);
        list.add(price);
        return list;
    }

    private void readObject(ObjectInputStream in) throws IOException {
        this.ad= String.valueOf(in.readChar());
    }

    public Computer(String brand, String ad, double price) {
        this.brand = brand;
        this.ad = ad;
        this.price = price;
    }

    public String getBrand() {
        return brand;
    }

    public void setBrand(String brand) {
        this.brand = brand;
    }

    public String getAd() {
        return ad;
    }

    public void setAd(String ad) {
        this.ad = ad;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    @Override
    public String toString() {
        return "Computer{" +
                "brand='" + brand + '\'' +
                ", ad='" + ad + '\'' +
                ", price=" + price +
                '}';
    }
}
